﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SynoManager.DownloadStation.Ftp
{
    public partial class FtpConnectionDialog : Form
    {
        public FtpConnectionDialog()
        {
            InitializeComponent();
        }

        public string Address
        {
            get { return addressTextBox.Text; }
        }

        public string Username
        {
            get { return usernameTextBox.Text;}
        }

        public string Password
        {
            get { return passwordTextBox.Text;}
        }

        public bool UsePassive
        {
            get { return passiveCheckBox.Checked; }
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            if (rememberSettingsCheckBox.Checked)
            {
                Properties.Settings.Default.FtpServer = addressTextBox.Text;
                Properties.Settings.Default.FtpUsername = usernameTextBox.Text;
                Properties.Settings.Default.FtpPassword = PasswordHelper.Protect(passwordTextBox.Text);
                Properties.Settings.Default.FtpUsePassive = passiveCheckBox.Checked;
            }

            DialogResult = DialogResult.OK;
        }

        private void FtpConnectionDialog_Load(object sender, EventArgs e)
        {
            addressTextBox.Text = Properties.Settings.Default.FtpServer;
            usernameTextBox.Text = Properties.Settings.Default.FtpUsername;
            passwordTextBox.Text = PasswordHelper.Unprotect(Properties.Settings.Default.FtpPassword);
            passiveCheckBox.Checked = Properties.Settings.Default.FtpUsePassive;
        }
    }
}
